package com.potato.model1.Fragment;

import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.potato.base.fragment.LazyFragment2;
import com.potato.model1.R;
import com.potato.model1.adapter.HPageAdapter;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends LazyFragment2 {

    private TabLayout mTabLayout;
    private ViewPager mHomeViewPager;
    private HPageAdapter mHpAdapter;

    public void initData() {
        List<String> titles =new ArrayList<>();
        titles.add("All");
        titles.add("Android");
        titles.add("ios");
        titles.add("前端");
        titles.add("拓展资源");
        List<Fragment> fragments =new ArrayList<>();
        fragments.add(HomeSubFragment.newInstance("all"));
        fragments.add(HomeSubFragment.newInstance("Android"));
        fragments.add(HomeSubFragment.newInstance("iOS"));
        fragments.add(HomeSubFragment.newInstance("前端"));
        fragments.add(HomeSubFragment.newInstance("拓展资源"));
        mHpAdapter=new HPageAdapter(titles,fragments,getChildFragmentManager());
        mHomeViewPager.setAdapter(mHpAdapter);
        mHomeViewPager.setOffscreenPageLimit(titles.size());
        mTabLayout.setupWithViewPager(mHomeViewPager);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.fragment_home;
    }

    @Override
    public void initView(View view) {
        mTabLayout=view.findViewById(R.id.tabLayout);
        mHomeViewPager=view.findViewById(R.id.homeViewPager);
        initData();
    }

    @Override
    protected void onFragmentFirstVisible() {

    }

}
